package com.example.dynamicdatasource.service;

import com.example.dynamicdatasource.config.annotation.DynamicDataSource;
import com.example.dynamicdatasource.mapper.ProvinceMapper;
import com.example.dynamicdatasource.pojo.Province;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ProvinceService {

    private final ProvinceMapper provinceMapper;

    /**
     * 根据省份编码查询省份信息
     * @param provinceCode 省份编码（如"beijing"、"shanghai"，对应数据源标识）
     */
    @DynamicDataSource(paramName = "#provinceCode")
    public Province getProvinceByCode(String provinceCode) {
        // Mapper层无需任何修改，自动使用切换后的数据源
        return provinceMapper.selectByCode(provinceCode);
    }

}
